load("//bzl:cpp_library.bzl", "cpp_library")
load("//bzl:cpp_unittest.bzl", "cpp_unittest")

package(default_visibility = ["//visibility:public"])

cpp_unittest(
    name = "ahm_int_stress_test",
    srcs = ["AHMIntStressTest.cpp"],
    deps = [
        "//folly:atomic_hash_map",
        "//folly:memory",
        "//folly:scope_guard",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "unicode_test",
    srcs = ["UnicodeTest.cpp"],
    deps = [
        "//folly:range",
        "//folly:unicode",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "arena_smart_ptr_test",
    srcs = ["ArenaSmartPtrTest.cpp"],
    deps = [
        "//folly:memory",
        "//folly/memory:arena",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "ascii_case_insensitive_test",
    srcs = ["AsciiCaseInsensitiveTest.cpp"],
    deps = [
        "//folly:range",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "base64_test",
    srcs = ["base64_test.cpp"],
    deps = [
        "//folly:base64",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "concurrent_bit_set_test",
    srcs = ["ConcurrentBitSetTest.cpp"],
    deps = [
        "//folly:concurrent_bit_set",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "buffered_atomic_test",
    srcs = ["BufferedAtomicTest.cpp"],
    deps = [
        ":deterministic_schedule",
        "//folly:singleton_thread_local",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "atomic_hash_array_test",
    srcs = ["AtomicHashArrayTest.cpp"],
    deps = [
        "//folly:atomic_hash_array",
        "//folly:conv",
        "//folly:memory",
        "//folly/hash",
        "//folly/portability:gtest",
        "//folly/portability:string",
        "//folly/portability:sys_mman",
    ],
)

cpp_unittest(
    name = "atomic_hash_map_test",
    size = "medium",
    srcs = ["AtomicHashMapTest.cpp"],
    deps = [
        "//folly:atomic_hash_map",
        "//folly:benchmark",
        "//folly:conv",
        "//folly/portability:atomic",
        "//folly/portability:gtest",
        "//folly/portability:sys_time",
        "@glog",
    ],
)

cpp_unittest(
    name = "atomic_linked_list_test",
    srcs = ["AtomicLinkedListTest.cpp"],
    deps = [
        "//folly:atomic_linked_list",
        "//folly:utility",
        "//folly/portability:gtest",
        "//folly/synchronization/test:barrier",
    ],
)

cpp_unittest(
    name = "atomic_unordered_map_test",
    srcs = ["AtomicUnorderedMapTest.cpp"],
    deps = [
        ":deterministic_schedule",
        "//folly:atomic_unordered_map",
        "//folly:benchmark",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
    ],
)

# NOTE: Parsing the output of the perf command seems to not be working as expected in this test.
# cpp_unittest(
#     name = "benchmark_test",
#     srcs = ["BenchmarkTest.cpp"],
#     deps = [
#         ":test_utils",
#         "//folly:benchmark",
#         "//folly/detail:perf_scoped",
#         "//folly/portability:gflags",
#         "//folly/portability:gmock",
#         "//folly/portability:gtest",
#     ],
# )

cpp_unittest(
    name = "cancellation_token_test",
    srcs = ["CancellationTokenTest.cpp"],
    deps = [
        "//folly:cancellation_token",
        "//folly:optional",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
)

cpp_unittest(
    name = "chrono_test",
    srcs = ["ChronoTest.cpp"],
    deps = [
        "//folly:chrono",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "clock_gettime_wrappers_test",
    srcs = ["ClockGettimeWrappersTest.cpp"],
    deps = [
        ":test_utils",
        "//folly:clock_gettime_wrappers",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "concurrent_lazy_test",
    srcs = ["ConcurrentLazyTest.cpp"],
    deps = [
        "//folly:concurrent_lazy",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "concurrent_skip_list_test",
    size = "medium",
    srcs = ["ConcurrentSkipListTest.cpp"],
    deps = [
        "//folly:concurrent_skip_list",
        "//folly:memory",
        "//folly:string",
        "//folly/container:foreach",
        "//folly/memory:arena",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "constexpr_math_test",
    srcs = ["ConstexprMathTest.cpp"],
    deps = [
        "//folly:constexpr_math",
        "//folly/lang:bits",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "constructor_callback_list_test",
    srcs = ["ConstructorCallbackListTest.cpp"],
    deps = [
        "//folly:constructor_callback_list",
        "//folly/portability:gtest",
    ],
)

cc_binary(
    name = "conv_benchmark",
    srcs = ["ConvBenchmark.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:conv",
        "//folly:cpp_attributes",
        "//folly/container:foreach",
        "//folly/lang:to_ascii",
        "@boost.conversion",
    ],
)

cpp_unittest(
    name = "conv_test",
    srcs = ["ConvTest.cpp"],
    deps = [
        "//folly:conv",
        "//folly:random",
        "//folly/container:foreach",
        "//folly/portability:gtest",
        "@fmt",
        "@glog",
    ],
)

cpp_unittest(
    name = "cpu_id_test",
    srcs = ["CpuIdTest.cpp"],
    deps = [
        "//folly:cpu_id",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "demangle_test",
    srcs = ["DemangleTest.cpp"],
    deps = [
        "//folly:demangle",
        "//folly/lang:pretty",
        "//folly/portability:gtest",
    ],
)

cpp_library(
    name = "deterministic_schedule",
    srcs = [
        "BufferedAtomic.cpp",
        "DeterministicSchedule.cpp",
    ],
    hdrs = [
        "BufferedAtomic.h",
        "DeterministicSchedule.h",
    ],
    deps = [
        "//folly:random",
        "//folly:scope_guard",
        "//folly:singleton_thread_local",
        "//folly/concurrency:cache_locality",
        "//folly/detail:futex",
        "//folly/lang:customization_point",
        "//folly/synchronization:atomic_notification",
        "//folly/synchronization/detail:atomic_utils",
        "//folly/synchronization/test:semaphore",
        "@glog",
    ],
)

cpp_unittest(
    name = "deterministic_schedule_test",
    srcs = ["DeterministicScheduleTest.cpp"],
    deps = [
        ":deterministic_schedule",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/synchronization:atomic_util",
    ],
)

cpp_unittest(
    name = "discriminated_ptr_test",
    srcs = ["DiscriminatedPtrTest.cpp"],
    deps = [
        "//folly:discriminated_ptr",
        "//folly/portability:gtest",
    ],
)

# This test depends only on :dynamic.  Tests which require other
# dependencies should be added to dynamic_other_test.

cpp_unittest(
    name = "endian_test",
    srcs = ["EndianTest.cpp"],
    deps = [
        "//folly/lang:bits",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "exception_string_test",
    srcs = ["ExceptionStringTest.cpp"],
    deps = [
        "//folly:exception_string",
        "//folly:portability",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "exception_test",
    srcs = ["ExceptionTest.cpp"],
    deps = [
        "//folly:exception",
        "//folly/portability:gtest",
        "//folly/testing:test_util",
    ],
)

cpp_unittest(
    name = "exception_wrapper_test",
    srcs = ["ExceptionWrapperTest.cpp"],
    deps = [
        "//folly:conv",
        "//folly:exception_wrapper",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "executor_test",
    srcs = ["ExecutorTest.cpp"],
    deps = [
        "//folly:executor",
        "//folly/lang:keep",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "expected_coroutines_test",
    srcs = ["ExpectedCoroutinesTest.cpp"],
    deps = [
        "//folly:expected",
        "//folly:portability",
        "//folly:scope_guard",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "expected_test",
    srcs = ["ExpectedTest.cpp"],
    deps = [
        "//folly:expected",
        "//folly/lang:keep",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "fbstring_test",
    srcs = ["FBStringTest.cpp"],
    deps = [
        ":test_utils",
        "//folly:conv",
        "//folly:fbstring",
        "//folly:portability",
        "//folly:random",
        "//folly:utility",
        "//folly/container:foreach",
        "//folly/portability:gtest",
        "@boost.algorithm",
        "@glog",
    ],
)

cpp_library(
    name = "fbvector_test_util",
    srcs = [
        "FBVectorTestUtil.cpp",
    ],
    hdrs = [
        "FBVectorTestUtil.h",
    ],
    deps = [
        "//folly:fbstring",
        "//folly:random",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "file_test",
    srcs = ["FileTest.cpp"],
    deps = [
        "//folly:file",
        "//folly:string",
        "//folly/portability:fcntl",
        "//folly/portability:filesystem",
        "//folly/portability:gtest",
        "@fmt",
        "@glog",
    ],
)

cpp_unittest(
    name = "file_lock_test",
    srcs = ["FileLockTest.cpp"],
    env = {
        "FOLLY_FILE_LOCK_TEST_HELPER": "$(rootpath :file_test_lock_helper)",
    },
    deps = [
        ":file_test_lock_helper",
        "//folly:file",
        "//folly:string",
        "//folly:subprocess",
        "//folly/experimental/io:fs_util",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/testing:test_util",
        "@boost.thread",
        "@glog",
    ],
)

cc_binary(
    name = "file_test_lock_helper",
    srcs = ["FileTestLockHelper.cpp"],
    deps = [
        "//folly:file",
        "//folly/portability:gflags",
        "@glog",
    ],
)

cpp_unittest(
    name = "file_util_test",
    srcs = ["FileUtilTest.cpp"],
    linkopts = select({
        "@platforms//os:linux": ["-ldl"],
        "//conditions:default": [],
    }),
    deps = [
        "//folly:exception",
        "//folly:file",
        "//folly:file_util",
        "//folly:range",
        "//folly:string",
        "//folly/detail:file_util_detail",
        "//folly/detail:file_util_vector_detail",
        "//folly/portability:gtest",
        "//folly/testing:test_util",
        "@glog",
    ],
)

cpp_unittest(
    name = "fingerprint_test",
    srcs = ["FingerprintTest.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:fingerprint",
        "//folly/detail:slow_fingerprint",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "fixed_string_test",
    srcs = ["FixedStringTest.cpp"],
    deps = [
        "//folly:fixed_string",
        "//folly:range",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "fmt_utility_test",
    srcs = ["FmtUtilityTest.cpp"],
    deps = [
        "//folly:fmt_utility",
    ],
)

# This test depends only on :format.  Tests for user-defined formatters
# should be added to format_other_test.
cpp_unittest(
    name = "format_test",
    srcs = ["FormatTest.cpp"],
    deps = [
        "//folly:format",
        "//folly:utility",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "format_other_test",
    srcs = ["FormatOtherTest.cpp"],
    deps = [
        "//folly:fbvector",
        "//folly:file_util",
        "//folly:format",
        "//folly:portability",
        "//folly:small_vector",
        "//folly/json:dynamic",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "function_ref_test",
    srcs = ["FunctionRefTest.cpp"],
    deps = [
        "//folly:function",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "function_test",
    srcs = ["FunctionTest.cpp"],
    deps = [
        "//folly:function",
        "//folly:memory",
        "//folly/lang:keep",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "futex_test",
    srcs = ["FutexTest.cpp"],
    deps = [
        ":deterministic_schedule",
        "//folly:chrono",
        "//folly/detail:futex",
        "//folly/portability:gtest",
        "//folly/portability:time",
        "@glog",
    ],
)

cpp_unittest(
    name = "group_varint_test",
    srcs = ["GroupVarintTest.cpp"],
    deps = [
        "//folly:group_varint",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "group_varint_test_ssse3",
    srcs = ["GroupVarintTest.cpp"],
    copts = ["-mssse3"],
    target_compatible_with = ["@platforms//cpu:x86_64"],
    deps = [
        "//folly:group_varint",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "indestructible_test",
    srcs = ["IndestructibleTest.cpp"],
    deps = [
        "//folly:indestructible",
        "//folly:memory",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "indexed_mem_pool_test",
    srcs = ["IndexedMemPoolTest.cpp"],
    deps = [
        ":deterministic_schedule",
        "//folly:indexed_mem_pool",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "//folly/portability:unistd",
    ],
)

cpp_unittest(
    name = "ip_address_test",
    srcs = ["IPAddressTest.cpp"],
    deps = [
        "//folly:network_address",
        "//folly:string",
        "//folly/container:bit_iterator",
        "//folly/detail:ip_address_source",
        "//folly/lang:bits",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "@fmt",
    ],
)

cpp_unittest(
    name = "iterators_test",
    srcs = ["IteratorsTest.cpp"],
    deps = [
        "//folly/container:array",
        "//folly/detail:iterators",
        "//folly/portability:gtest",
        "//folly/portability:sys_types",
    ],
)

# This test depends only on :json.  Tests which require other
# dependencies should be added to json_other_test.

cpp_unittest(
    name = "lazy_test",
    srcs = ["LazyTest.cpp"],
    deps = [
        "//folly:lazy",
        "//folly/portability:gtest",
    ],
)

cc_binary(
    name = "glog_benchmark",
    srcs = ["GLogBenchmark.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:glog",
    ],
)

cpp_unittest(
    name = "glog_test",
    srcs = ["GLogTest.cpp"],
    deps = [
        "//folly:glog",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "mac_address_test",
    srcs = ["MacAddressTest.cpp"],
    deps = [
        "//folly:network_address",
        "//folly/portability:gtest",
        "@fmt",
    ],
)

cc_binary(
    name = "math_benchmark",
    srcs = ["MathBenchmark.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:math",
    ],
)

cpp_unittest(
    name = "math_test",
    srcs = ["MathTest.cpp"],
    deps = [
        "//folly:math",
        "//folly:portability",
        "//folly/functional:invoke",
        "//folly/portability:gtest",
        "@glog",
    ],
)

# Test MaybeManagedPtr with default settings and on c++17 and c++20.
# We test c++17 and c++20 explicitly since c++20 can synthesize `operator!=` whereas c++17 cannot.
cpp_unittest(
    name = "maybe_managed_ptr_test",
    srcs = ["MaybeManagedPtrTest.cpp"],
    deps = [
        "//folly:maybe_managed_ptr",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "maybe_managed_ptr_test_c++17",
    srcs = ["MaybeManagedPtrTest.cpp"],
    copts = [
        "-std=c++17",
    ],
    deps = [
        "//folly:maybe_managed_ptr",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "maybe_managed_ptr_test_c++20",
    srcs = ["MaybeManagedPtrTest.cpp"],
    deps = [
        "//folly:maybe_managed_ptr",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "memset_test",
    srcs = [
        "MemsetTest.cpp",
    ],
    deps = [
        "//folly:memset",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "memcpy_test",
    srcs = ["MemcpyTest.cpp"],
    deps = [
        "//folly:memcpy",
        "//folly:portability",
        "//folly/portability:gtest",
        "//folly/portability:sys_types",
    ],
)

cc_binary(
    name = "memcpy_benchmark",
    srcs = ["MemcpyBenchmark.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:memcpy",
        "//folly/portability:unistd",
    ],
)

cpp_unittest(
    name = "memcpy_use_test",
    srcs = ["MemcpyUseTest.cpp"],
    deps = [
        "//folly:memcpy-use",  # @manual
        "//folly/lang:keep",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "memory_test",
    srcs = ["MemoryTest.cpp"],
    deps = [
        "//folly:constexpr_math",
        "//folly:memory",
        "//folly:string",
        "//folly/lang:keep",
        "//folly/memory:arena",
        "//folly/portability:asm",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cc_binary(
    name = "memory_idler_benchmark",
    srcs = ["MemoryIdlerBenchmark.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly/detail:memory_idler",
    ],
)

cpp_unittest(
    name = "memory_idler_test",
    srcs = ["MemoryIdlerTest.cpp"],
    deps = [
        "//folly/detail:memory_idler",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
)

cpp_unittest(
    name = "move_wrapper_test",
    srcs = ["MoveWrapperTest.cpp"],
    deps = [
        "//folly:move_wrapper",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "mpmc_pipeline_test",
    srcs = ["MPMCPipelineTest.cpp"],
    deps = [
        "//folly:conv",
        "//folly:mpmc_pipeline",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "mpmc_queue_test",
    srcs = ["MPMCQueueTest.cpp"],
    deps = [
        ":deterministic_schedule",
        "//folly:format",
        "//folly:memory",
        "//folly:mpmc_queue",
        "//folly:stop_watch",
        "//folly/portability:gtest",
        "//folly/portability:sys_resource",
        "//folly/portability:sys_time",
        "//folly/portability:unistd",
        "@boost.intrusive",
        "@boost.thread",
    ],
)

cpp_library(
    name = "observer_container_test_util",
    hdrs = ["ObserverContainerTestUtil.h"],
    deps = [
        "//folly:function",
        "//folly:optional",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

# TODO(kgk): Fix test.
# cpp_unittest(
#     name = "observer_container_test",
#     srcs = ["ObserverContainerTest.cpp"],
#     # Prevents error due to masking name ObserverContainer.
#     copts = ["-fpermissive"],
#     deps = [
#         ":observer_container_test_util",
#         "//folly:observer_container",
#         "//folly/portability:gmock",
#         "//folly/portability:gtest",
#     ],
# )

cpp_unittest(
    name = "optional_test",
    srcs = ["OptionalTest.cpp"],
    deps = [
        "//folly:optional",
        "//folly:portability",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "optional_coroutines_test",
    srcs = ["OptionalCoroutinesTest.cpp"],
    deps = [
        "//folly:optional",
        "//folly:portability",
        "//folly:scope_guard",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "replaceable_test",
    srcs = ["ReplaceableTest.cpp"],
    deps = [
        "//folly:replaceable",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "overload_test",
    srcs = ["OverloadTest.cpp"],
    deps = [
        "//folly:discriminated_ptr",
        "//folly:overload",
        "//folly/portability:gtest",
        "@boost.variant",
    ],
)

cpp_unittest(
    name = "packed_sync_ptr_test",
    srcs = ["PackedSyncPtrTest.cpp"],
    deps = [
        "//folly:packed_sync_ptr",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "padded_test",
    srcs = ["PaddedTest.cpp"],
    deps = [
        "//folly:padded",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "poly_test",
    srcs = ["PolyTest.cpp"],
    deps = [
        "//folly:conv",
        "//folly:poly",
        "//folly/poly:basic_interfaces",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "portability_test",
    srcs = ["PortabilityTest.cpp"],
    deps = [
        "//folly:portability",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "producer_consumer_queue_test",
    srcs = ["ProducerConsumerQueueTest.cpp"],
    deps = [
        "//folly:producer_consumer_queue",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cc_binary(
    name = "random_benchmark",
    srcs = ["RandomBenchmark.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:random",
        "//folly/container:foreach",
        "@glog",
    ],
)

cpp_unittest(
    name = "random_test",
    srcs = ["RandomTest.cpp"],
    deps = [
        "//folly:random",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "range_test",
    srcs = ["RangeTest.cpp"],
    deps = [
        "//folly:cpp_attributes",
        "//folly:memory",
        "//folly:range",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "//folly/portability:sys_mman",
        "//folly/portability:unistd",
        "@boost.algorithm",
        "@boost.range",
        "@range-v3",
    ],
)

cpp_unittest(
    name = "scope_guard_test",
    srcs = ["ScopeGuardTest.cpp"],
    deps = [
        "//folly:scope_guard",
        "//folly/lang:keep",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "shared_mutex_test",
    srcs = ["SharedMutexTest.cpp"],
    deps = [
        ":deterministic_schedule",
        ":test_utils",
        "//folly:benchmark",
        "//folly:mpmc_queue",
        "//folly:shared_mutex",
        "//folly/fibers:core",
        "//folly/fibers:timed_mutex",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/synchronization:rw_spin_lock",
        "@boost.thread",
    ],
)

# TODO(kgk): Fix test.
# cpp_unittest(
#     name = "singleton_test",
#     srcs = ["SingletonTest.cpp"],
#     deps = [
#         ":singleton_test_structs",
#         ":test_utils",
#         "//folly:singleton",
#         "//folly/io/async:async_base",
#         "//folly/portability:gmock",
#         "//folly/portability:gtest",
#         "@boost.thread",
#         "@glog",
#     ],
# )

cpp_unittest(
    name = "singleton_test_global",
    srcs = ["SingletonTestGlobal.cpp"],
    deps = [
        ":singleton_test_structs",
        "//folly:benchmark",
        "//folly:singleton",
        "//folly/portability:gtest",
    ],
)

cpp_library(
    name = "singleton_test_structs",
    srcs = ["SingletonTestStructs.cpp"],
    hdrs = ["SingletonTestStructs.h"],
    deps = [
        "//folly/portability:gtest",
        "@glog",
    ],
)

cc_binary(
    name = "singleton_thread_local_overload.so",
    srcs = ["SingletonThreadLocalTestOverload.cpp"],
    linkshared = 1,
    deps = [
        "//folly:singleton_thread_local",
    ],
)

cpp_unittest(
    name = "singleton_thread_local_test",
    srcs = ["SingletonThreadLocalTest.cpp"],
    data = [
        ":singleton_thread_local_overload.so",  # @manual
    ],
    linkopts = select({
        "@platforms//os:linux": ["-ldl"],
        "//conditions:default": [],
    }),
    deps = [
        ":singleton_thread_local_overload.so",  # @manual
        "//folly:singleton_thread_local",
        "//folly:string",
        "//folly:synchronized",
        "//folly/experimental/io:fs_util",
        "//folly/lang:keep",
        "//folly/portability:gtest",
        "//folly/synchronization:latch",
        "//folly/testing:test_util",
        "@boost.thread",
    ],
)

cpp_unittest(
    name = "socket_address_test",
    srcs = ["SocketAddressTest.cpp"],
    deps = [
        ":socket_address_test_helper",
        "//folly:network_address",
        "//folly:string",
        "//folly/container:array",
        "//folly/portability:gtest",
        "//folly/portability:sockets",
        "//folly/testing:test_util",
    ],
)

cpp_library(
    name = "socket_address_test_helper",
    srcs = ["SocketAddressTestHelper.cpp"],
    hdrs = ["SocketAddressTestHelper.h"],
    deps = [
        "//folly/portability:sockets",
    ],
)

cpp_unittest(
    name = "spin_lock_test",
    srcs = ["SpinLockTest.cpp"],
    deps = [
        "//folly:random",
        "//folly:spin_lock",
        "//folly:utility",
        "//folly/portability:asm",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "string_test",
    srcs = ["StringTest.cpp"],
    deps = [
        ":test_utils",
        "//folly:fbvector",
        "//folly:string",
        "//folly/container:array",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "@boost.regex",
        "@glog",
    ],
)

cpp_unittest(
    name = "subprocess_test",
    srcs = ["SubprocessTest.cpp"],
    data = [
        ":subprocess_test_parent_death_helper",
    ],
    deps = [
        ":subprocess_test_parent_death_helper",  # @manual
        "//folly:exception",
        "//folly:file_util",
        "//folly:format",
        "//folly:string",
        "//folly:subprocess",
        "//folly/experimental/io:fs_util",
        "//folly/gen:base",
        "//folly/gen:file",
        "//folly/gen:string",
        "//folly/portability:gtest",
        "//folly/portability:unistd",
        "//folly/testing:test_util",
        "@boost.container",
        "@glog",
    ],
)

cc_binary(
    name = "subprocess_test_parent_death_helper",
    srcs = ["SubprocessTestParentDeathHelper.cpp"],
    deps = [
        "//folly:conv",
        "//folly:subprocess",
        "//folly/portability:gflags",
        "//folly/portability:unistd",
        "@glog",
    ],
)

cpp_unittest(
    name = "synchronized_test",
    srcs = ["SynchronizedTest.cpp"],
    deps = [
        ":synchronized_test_lib",
        "//folly:function",
        "//folly:portability",
        "//folly:scope_guard",
        "//folly:shared_mutex",
        "//folly:spin_lock",
        "//folly:synchronized",
        "//folly/portability:gtest",
        "//folly/synchronization:distributed_mutex",
        "//folly/synchronization:rw_spin_lock",
    ],
)

cpp_unittest(
    name = "synchronized_ptr_test",
    srcs = ["SynchronizedPtrTest.cpp"],
    deps = [
        "//folly:optional",
        "//folly:replaceable",
        "//folly:synchronized_ptr",
        "//folly/portability:gtest",
        "//folly/synchronization:rw_spin_lock",
    ],
)

cpp_library(
    name = "synchronized_test_lib",
    hdrs = [
        "SynchronizedTestLib.h",
        "SynchronizedTestLib-inl.h",
    ],
    deps = [
        "//folly:random",
        "//folly:synchronized",
        "//folly/container:foreach",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_library(
    name = "test_utils",
    hdrs = ["TestUtils.h"],
    deps = [
        "//folly:conv",
        "//folly:exception_string",
        "//folly:fbstring",
        "//folly:fixed_string",
        "//folly:range",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "thread_cached_int_test",
    srcs = ["ThreadCachedIntTest.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:thread_cached_int",
        "//folly/container:foreach",
        "//folly/hash",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/system:thread_id",
        "@glog",
    ],
)

cc_binary(
    name = "thread_local_benchmark",
    srcs = ["ThreadLocalBenchmark.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:thread_local",
        "//folly/lang:keep",
        "//folly/portability:gflags",
        "//folly/synchronization:latch",
        "@boost.thread",
        "@glog",
    ],
)

cpp_unittest(
    name = "timeout_queue_test",
    srcs = ["TimeoutQueueTest.cpp"],
    deps = [
        "//folly:timeout_queue",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "token_bucket_test",
    srcs = [
        "TokenBucketTest.cpp",
        "TokenBucketTest.h",
    ],
    deps = [
        "//folly:string",
        "//folly:token_bucket",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "traits_test",
    srcs = ["TraitsTest.cpp"],
    deps = [
        "//folly:cpp_attributes",
        "//folly:scope_guard",
        "//folly:traits",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "try_test",
    srcs = ["TryTest.cpp"],
    deps = [
        "//folly:traits",
        "//folly:try",
        "//folly/lang:exception",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "unit_test",
    srcs = ["UnitTest.cpp"],
    deps = [
        "//folly:unit",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "uri_test",
    srcs = ["UriTest.cpp"],
    deps = [
        "//folly:uri",
        "//folly/portability:gtest",
        "@boost.algorithm",
        "@glog",
    ],
)

cpp_unittest(
    name = "utf8_string_test",
    srcs = ["UTF8StringTest.cpp"],
    deps = [
        ":test_utils",
        "//folly:range",
        "//folly:utf8_string",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "utility_test",
    srcs = ["UtilityTest.cpp"],
    deps = [
        "//folly:utility",
        "//folly/lang:keep",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "varint_test",
    srcs = ["VarintTest.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:random",
        "//folly:varint",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_library(
    name = "json_mock_util",
    hdrs = [
        "JsonMockUtil.h",
    ],
    deps = [
        "//folly/json:json_mock_util",
    ],
)

cpp_library(
    name = "json_test_util",
    hdrs = [
        "JsonTestUtil.h",
    ],
    deps = [
        "//folly/json:json_test_util",
    ],
)

cpp_unittest(
    name = "test_utils_test",
    srcs = ["TestUtilsTest.cpp"],
    deps = [
        ":test_utils",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_library(
    name = "comparison_operator_test_util",
    hdrs = ["ComparisonOperatorTestUtil.h"],
    deps = [
        "//folly/portability:gtest",
    ],
)
